<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*====== 1.数组的结构赋值 ======*/
        const arr1 = [1,2,3,4];
        // 如果你想要从数组中提取值，则你用于提取的结构必须是个数组
        const [a,b,c,d] = arr1;
        console.log(a); //1
        console.log(b); //2
        console.log(c); //3
        console.log(d); //4

        const arr2 = [1,[2,3,4],5];
        // 如果不想提取，可以用逗号跳过
        const [a1,[,,b1],c1] = arr2;
        console.log(a1); //1
        console.log(b1); //4
        console.log(c1); //5

        const arr3 = [];
        // 解构赋值可以给出默认值，默认值只有在数组成员严格等于(===)undefined时才会生效
        const [a2,b2,c2 = 1] = arr3;
        console.log(a2); //undefined
        console.log(b2); //undefined
        console.log(c2); //1

        function fn1(a,b){
            console.log(arguments);
            // 解构赋值可以是数组提取伪数组
            const [a4,b4] = arguments;
            console.log(a4);
            console.log(b4);
        }
        fn1(1,2)

        /*====== 2.对象的结构赋值 ======*/
        const person = {
            uname: 'ArimaMisaki',
            age: 13,
            say:function(){
                console.log("会说话");
            }
        }
        // 如果你想要从对象中提取值，则你用于提取的结构必须是个对象
        const {uname:name,age:age,say:sayfn} = person; //对应写法
        // const {uname,age,sayfn} = person; //老写法
        console.log(name,age);
        sayfn();
    </script>
</body>
</html>